package com.itcam.controller;

import com.itcam.pojo.Dept;
import com.itcam.pojo.Result;
import com.itcam.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理Controller
 */
@RestController
@Slf4j
@RequestMapping("/depts")
public class DeptController {

    @Autowired

    public DeptService deptService;

    @GetMapping
    public Result list() {
        log.info("查询全部的部门数据");

        // 调用service查询部门数据
        List<Dept> deptList = deptService.selectAll();

        return Result.success(deptList);
    }

    @DeleteMapping("/{id}")
    public Result deleteDept(@PathVariable Integer id) {
        log.info("删除部门，id为{}", id);
        // 调用service删除部门
        deptService.deleteById(id);
        return Result.success();
    }

    /**
     * 添加部门
     *
     * @param dept
     * @return
     */
    @PostMapping
    public Result addDept(@RequestBody Dept dept) {

        log.info("添加部门，信息为{}", dept);
        // 调用service添加部门
        deptService.addDept(dept);
        return Result.success();
    }
}
